/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.mobdev.notepad;

import android.content.Intent;
import android.net.Uri;
import android.preference.PreferenceManager;

import com.mobdev.notepad.shared.ui.AbstractNotesList;
import com.mobdev.notepad.sync.SyncActivity;

/**
 * Displays a list of notes. Will display notes from the {@link Uri}
 * provided in the intent if there is one, otherwise defaults to displaying the
 * contents of the {@link NotePadProvider}
 */
public class NotesList extends AbstractNotesList {

    @Override
    protected void init() {


        /*
         * Load the default values so they're set even if the user does not go into the preferences
         * screen.
         */
        PreferenceManager.setDefaultValues(this, R.xml.preferences, false);



        // If no data was given in the intent (because we were started
        // as a MAIN activity), then use our default content provider.
        Intent intent = getIntent();
        if (intent.getData() == null) {
            intent.setData(NotepadProvider.NOTEPAD_URI);
        }

        updateList();

        setContentView(R.layout.noteslist);
    }


	@Override
	protected int getNotesListItemId()
	{
		return R.layout.noteslist_item;
	}

	@Override
	protected int getSyncMenuIconId()
	{
		return R.drawable.sync_48;
	}

	@Override
	protected void doEditTitle(Uri mUri)
	{
		startActivity(new Intent(this, TitleEditor.class).setData(mUri));
	}


	@Override
	protected void doEditNote(Uri mUri, String action)
	{
		startActivity(new Intent(this, NoteEditor.class).setData(mUri).setAction(action));
	}

	@Override
	protected void doSync()
	{
		// Launch activity to sync notes with helipad
		startActivity(new Intent(this, SyncActivity.class));
	}

	@Override
	protected void doPreferences()
	{
		startActivityForResult(new Intent(this, PreferencesActivity.class), REQUEST_CODE_PREFERENCES );
	}

	@Override
	protected String getLocalyticsAppKey() {

		return NotepadProvider.LOCALYTICS_APP_KEY;  // Key generated on the webservice
	}
}
